package com.ruoyi.business.service.impl;

import java.util.List;

import com.ruoyi.business.domain.enums.GradeLevelEnum;
import com.ruoyi.business.domain.enums.HeightWeightGradeEnum;
import com.ruoyi.business.domain.enums.ProjectTypeEnum;
import com.ruoyi.common.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.business.mapper.SchoolProjectStandardMapper;
import com.ruoyi.business.domain.SchoolProjectStandard;
import com.ruoyi.business.service.ISchoolProjectStandardService;
import org.springframework.util.ObjectUtils;

/**
 * 学校项目标准Service业务层处理
 * 
 * @author lcz
 * @date 2025-02-23
 */
@Service
public class SchoolProjectStandardServiceImpl implements ISchoolProjectStandardService 
{
    @Autowired
    private SchoolProjectStandardMapper schoolProjectStandardMapper;

    /**
     * 查询学校项目标准
     * 
     * @param id 学校项目标准主键
     * @return 学校项目标准
     */
    @Override
    public SchoolProjectStandard selectSchoolProjectStandardById(Long id)
    {
        return schoolProjectStandardMapper.selectSchoolProjectStandardById(id);
    }

    /**
     * 查询学校项目标准列表
     * 
     * @param schoolProjectStandard 学校项目标准
     * @return 学校项目标准
     */
    @Override
    public List<SchoolProjectStandard> selectSchoolProjectStandardList(SchoolProjectStandard schoolProjectStandard)
    {
        return schoolProjectStandardMapper.selectSchoolProjectStandardList(schoolProjectStandard);
    }

    /**
     * 新增学校项目标准
     * 
     * @param schoolProjectStandard 学校项目标准
     * @return 结果
     */
    @Override
    public int insertSchoolProjectStandard(SchoolProjectStandard schoolProjectStandard)
    {
        schoolProjectStandard.setCreateTime(DateUtils.getNowDate());
        if (schoolProjectStandard.getProjectType().equals(ProjectTypeEnum.HEIGHT.getCode())){
            schoolProjectStandard.setGradeName(HeightWeightGradeEnum.getGrade(schoolProjectStandard.getGradeId()).getValue());
        }else {
            schoolProjectStandard.setGradeName(GradeLevelEnum.getGrade(schoolProjectStandard.getGradeId()).getValue());
        }
        return schoolProjectStandardMapper.insertSchoolProjectStandard(schoolProjectStandard);
    }

    /**
     * 修改学校项目标准
     * 
     * @param schoolProjectStandard 学校项目标准
     * @return 结果
     */
    @Override
    public int updateSchoolProjectStandard(SchoolProjectStandard schoolProjectStandard)
    {
        schoolProjectStandard.setUpdateTime(DateUtils.getNowDate());
        if (!ObjectUtils.isEmpty(schoolProjectStandard.getGradeId())) {
            if (schoolProjectStandard.getProjectType().equals(ProjectTypeEnum.HEIGHT.getCode())){
                schoolProjectStandard.setGradeName(HeightWeightGradeEnum.getGrade(schoolProjectStandard.getGradeId()).getValue());
            }else {
                schoolProjectStandard.setGradeName(GradeLevelEnum.getGrade(schoolProjectStandard.getGradeId()).getValue());
            }
        }
        return schoolProjectStandardMapper.updateSchoolProjectStandard(schoolProjectStandard);
    }

    /**
     * 批量删除学校项目标准
     * 
     * @param ids 需要删除的学校项目标准主键
     * @return 结果
     */
    @Override
    public int deleteSchoolProjectStandardByIds(Long[] ids)
    {
        return schoolProjectStandardMapper.deleteSchoolProjectStandardByIds(ids);
    }

    /**
     * 删除学校项目标准信息
     * 
     * @param id 学校项目标准主键
     * @return 结果
     */
    @Override
    public int deleteSchoolProjectStandardById(Long id)
    {
        return schoolProjectStandardMapper.deleteSchoolProjectStandardById(id);
    }
}
